package com.egov.config.annotation.dic;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;


import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @Author: denggang
 * @Date: 2018-09-11 9:16
 **/
public class DicSerializer extends JsonSerializer<Object> {

    //字典表名
    protected String tableName;

    //字典表code字段名
    protected String colName;

    //字典表code对应的显示值
    protected String valueName;

    //字典表code分组的 字段名
    protected String codeTypeValue;

    //字典表code分组值
    protected String codeType;

    public DicSerializer(String colName, String valueName,String codeTypeValue) {
        this.tableName = tableName;
        this.colName = colName;
        this.valueName = valueName;
        this.codeTypeValue = codeTypeValue;
        this.codeType = codeType;
    }

    @Override
    public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider)
            throws IOException, JsonProcessingException {
        Map<String,Object> map = new HashMap<>();
//        map.put("tableName",tableName);
        map.put("colName",colName);
        map.put("valueName",valueName);
        map.put("codeTypeValue",codeTypeValue);
//        map.put("codeType",codeType);

        //实体类字段对应值
        map.put("code",String.valueOf(value));

        jgen.writeObject(DicUtils.getDic(map));
    }
}